import numpy as np
import lmdb
import caffe
from caffe.proto import caffe_pb2


img_lmdb = lmdb.open("/home/sunzy/workspace/pyhome/CaffeProject/CaffeProject/pulsar/deep_learning/temp/mnist/mnist_train_lmdb")
txn = img_lmdb.begin()
cursor = txn.cursor()
datum = caffe_pb2.Datum()
for (idx, (key, value)) in enumerate(cursor):
    datum.ParseFromString(value)
    flat_x = np.fromstring(datum.data, dtype=np.uint8)
    x = flat_x.reshape(datum.channels, datum.height, datum.width)
    y = datum.label
    print(x.shape, y)

